package org.example.service.impl;

import org.example.entity.Fruit;
import org.example.service.QuestionsService;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

@Service
public class QuestionsServiceImpl implements QuestionsService {


    /**
     * 计算总价格
     * @param fruit
     * @return
     */
    @Override
    public BigDecimal calculatePrice(Fruit[] fruit) {
        BigDecimal tatolPrice = new BigDecimal(0);
        for (Fruit value : fruit) {
            tatolPrice = tatolPrice.add(value.getPrice().multiply(new BigDecimal(String.valueOf(value.getWeight()))));
        }
        return tatolPrice;
    }
}
